package com.qianxp.designparttern.prototype;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.List;


import lombok.Data;
/**
 *@author qianxp
 */
@Data
@SuppressWarnings("unchecked")
public class Student implements Cloneable,Serializable{
    /**
     *
     */
    private static final long serialVersionUID = 83586126035074662L;

    private Long id;

    private String name;

    private String sex;

    private String CardNo;

    private String address;

    private List<Book> books;
    
    private Student(){

    }

    private static Student instance = new Student();

    public static Student getInstance(){
        return instance;
    }
     

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    protected <T>T deepClone() {
        String path = "d.temp";
        try(
            ObjectOutputStream objectOut = new ObjectOutputStream(new FileOutputStream(path));
            ObjectInputStream objectIn = new ObjectInputStream(new FileInputStream(path))
        ){
            objectOut.writeObject(this);
            objectOut.flush();
            return (T)objectIn.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
       
       
        
    }

}